<?php

namespace app\modules\Admin\models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use memberModel;

class memberwalletrechargeModel extends Model
{
    protected $table = 'member_wallet_recharge';
    protected $primaryKey = 'id';
    protected $appends = ['payment_text', 'status_text'];

    protected static array $paymentes = [
        'wechat'=>'微信',
        'alipay'=>'支付宝',
        'JoinPay-wx'=>'JoinPay微信',
        'JoinPay-ali'=>'JoinPay支付宝',
    ];

    /**
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    /**
     * @return string
     */
    public function getPaymentTextAttribute()
    {
        $payment_text = '';
        $payment__key = array_keys(self::$paymentes);
        if(in_array($this->attributes['payment'], $payment__key)){
            $payment_text = self::$paymentes[$this->attributes['payment']];
        }
        unset($payment__key);
        return $payment_text;
    }

    /**
     * @return string
     */
    public function getStatusTextAttribute()
    {
        $status_text = '';
        if(in_array($this->attributes['status'], ['0', '1'])){
            $status_text = $this->attributes['status'] == 1?'充值完成':'待支付';
        }
        return $status_text;
    }


    public function getMember()
    {
        return $this->hasOne(memberModel::class, 'id', 'member_id')->select(['id', 'phone', 'nickname', 'realname', 'avatar']);
    }
}